package com.qiaofang.controller;

import com.qiaofang.common.response.CommonResponse;
import com.qiaofang.common.response.SuccessfulResponseFactory;
import com.qiaofang.constant.CompanyTypeEnum;
import com.qiaofang.dto.CompanyDTO;
import com.qiaofang.dto.ListApiLogDTO;
import com.qiaofang.dto.ListCompanyDTO;
import com.qiaofang.request.*;
import com.qiaofang.response.GetCompanyResponse;
import com.qiaofang.response.ListApiLogResponse;
import com.qiaofang.response.ListCompanyResponse;
import com.qiaofang.response.ListOptionCompanyResponse;
import com.qiaofang.service.ApiLogService;
import com.qiaofang.service.MerchantCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Api(tags = {"接口日志"})
@RequestMapping(value = "/systemApiLog", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public class ApiLogController {

    @Autowired
    private ApiLogService apiLogService;

    @PostMapping(value = "/listApiLog")
    @ApiOperation(value = "查询列表")
    public ListApiLogResponse listApiLog(@RequestBody ListApiLogRequest request) {
        ListApiLogResponse response = new ListApiLogResponse();

        ListApiLogDTO dto = new ListApiLogDTO();
        dto.setApiType(request.getApiType());
        dto.setCreateTimeStart(request.getCreateTimeStart());
        dto.setCreateTimeEnd(request.getCreateTimeEnd());
        dto.setSearchContent(request.getSearchContent());
        response.setData(apiLogService.listApiLog(dto, request.getPage()));
        return response;
    }

    @PostMapping(value = "/sendApiLogAgain")
    @ApiOperation(value = "删除")
    public CommonResponse sendApiLogAgain(@RequestBody @Valid SendApiLogAgainRequest request) {
        CommonResponse response = apiLogService.sendApiLogAgain(request.getId());
        return response;
    }

}
